Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ #120019

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

blhsing
Copy link
Contributor

@blhsing blhsing commented Jun 4, 2024

Avoid triggering call to a PropertyMock in NonCallableMock.__setattr__

Previously attaching a PropertyMock to a mock object would trigger a call to the property mock due to a recursive __setattr__ call.

This is now fixed by setting the given property mock as an attribute of the hosting mock directly in its __dict__ instead.

Copy link
Contributor

@cjw296 cjw296 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do you consider this a bugfix or a feature improvement?

@blhsing
Copy link
Contributor Author

blhsing commented Jun 10, 2024

LGTM. Do you consider this a bugfix or a feature improvement?

Thanks. I believe this is a bug (it was filed as one) since it should be expected that a PropertyMock does not trigger a call just by attaching it to another mock object, a common initialization setup.

@cjw296 cjw296 added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Jun 11, 2024
@cjw296 cjw296 enabled auto-merge (squash) June 11, 2024 05:42
@cjw296 cjw296 merged commit 9e9ee50 into python:main Jun 11, 2024
37 checks passed
@miss-islington-app
Copy link

Thanks @blhsing for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2024
…eMock.__setattr__ (pythonGH-120019)

(cherry picked from commit 9e9ee50)

Co-authored-by: blhsing <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2024
…eMock.__setattr__ (pythonGH-120019)

(cherry picked from commit 9e9ee50)

Co-authored-by: blhsing <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Jun 11, 2024

GH-120336 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jun 11, 2024
@bedevere-app
Copy link

bedevere-app bot commented Jun 11, 2024

GH-120337 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Jun 11, 2024
cjw296 pushed a commit that referenced this pull request Jun 11, 2024
…leMock.__setattr__ (GH-120019) (#120337)

gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019)
(cherry picked from commit 9e9ee50)

Co-authored-by: blhsing <[email protected]>
cjw296 pushed a commit that referenced this pull request Jun 11, 2024
…leMock.__setattr__ (GH-120019) (#120336)

gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (GH-120019)
(cherry picked from commit 9e9ee50)

Co-authored-by: blhsing <[email protected]>
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants